apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service"], function(V, $api, $, app, service) {
        var vm = {
            el: '.container',
            data: {
                order_id: '',
                order_return_id: '',
                orderDetail: '',
                refundDetail: '',
                reasonList: [],
                picked: '',
                refuse_explain: '',
            },
            mounted: function() {

            },
            methods: {
                // refuseReturnOrder
                //--跳转到商品预览页面
                openGoodsDetail: function(goodsId) {
                    app.openWin('buyGoods', {
                        goodsId: goodsId,
                        isSeller: 1
                    })
                },
                //--原因选择
                refuseCauseSelect: function(et) {
                    this.$refs.orderRefuseCause.style.display = "block";
                },
                //--关闭拒绝原因列表（点击模态框事件）
                close_order_refuse_cause: function() {
                    this.$refs.orderRefuseCause.style.display = "none";
                    this.picked = '';
                },
                //--确认选择理由
                selectReasonConfirm: function() {
                    this.$refs.orderRefuseCause.style.display = "none";
                    var checked_reason = $('input[type="radio"]:checked').siblings('span').html()
                    $('.reason_tag').html(checked_reason)
                },
                commit: function() {
                    var unionid = $api.getStorage('shop_unionid');
                    var reply_remark = this.refuse_explain;
                    var order_return_id = this.order_return_id;

                    if (this.picked == '') {
                        api.toast({
                            msg: '请选择拒绝原因...',
                            duration: 2000,
                            location: 'middle'
                        });
                        return
                    } else {
                        var picked = this.picked;
                    }

                    app.ajax(service['refuseReturnOrder'], {
                            data: {
                                values: {
                                    unionid: unionid,
                                    reply: picked,
                                    reply_remark: reply_remark,
                                    order_return_id: order_return_id
                                }
                            }
                        },
                        function(res) {
                            if (res.code) {
                                alert("错误代码code：" + res.code + "\n错误信息：" + res.message)
                            } else {
                                console.log("拒绝退款成功");
                                console.log(JSON.stringify(res.data));
                                api.sendEvent({
                                    name: 'close_win_refresh',
                                    extra: {
                                        shopId: api.pageParam.shopId,
                                    }
                                });
                                api.closeWin();
                            }
                        });

                },
            },
            created: function() {
                var that = this;
                this.order_id = api.pageParam.order_id;
                var unionid = $api.getStorage('shop_unionid');

                app.ajax(service['orderDetailGet'], {
                        data: {
                            values: {
                                unionid: unionid,
                                order_id: this.order_id
                            }
                        }
                    },
                    function(res) {
                        if (res.code) {
                            alert("错误代码code：" + res.code + "\n错误信息：" + res.message)
                        } else {
                            console.log("获取订单详情成功");
                            that.orderDetail = res.data;
                            that.refundDetail = res.data.refund;
                            that.order_return_id = res.data.refund.order_return_id;
                            console.log(JSON.stringify(that.orderDetail));
                        }
                    });

                app.ajax(service['getSellerReasonList'], {
                        data: {
                            values: {
                                unionid: unionid,
                                order_id: this.order_id
                            }
                        }
                    },
                    function(res) {
                        if (res.code) {
                            alert("错误代码code：" + res.code + "\n错误信息：" + res.message)
                        } else {
                            console.log("获取拒绝退款理由列表 成功");
                            that.reasonList = res.data;

                            console.log(JSON.stringify(that.reasonList));
                        }
                    });

            },
        };

        var even = function() {

        };
        var newVue = new Vue(vm);
        even();

    })
}
